/*
 * MIT License
 *
 * Copyright (c) 2023-present, tangli
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */

package tony.mybatis.datascope.handler

import net.sf.jsqlparser.expression.Expression
import net.sf.jsqlparser.schema.Table
import tony.mybatis.datascope.model.DataScopeValue

/**
 * [tony.mybatis.datascope.IDataScopeContext] 驱动的 支持多表的数据权限处理器
 * @author tangli
 * @date 2025/09/15 16:38
 */
public interface ScopedDataPermissionHandler {
    /**
     * 获取数据权限 SQL 片段。
     *
     * @param table             所执行的数据库表信息，可以通过此参数获取表名和表别名
     * @param where             原有的 where 条件信息
     * @param mappedStatementId Mybatis MappedStatement id 根据该参数可以判断具体执行方法
     * @param dataScopeValue         数据权限上下文
     * @return JSqlParser 条件表达式，返回的条件表达式会拼接在原有的表达式后面（不会覆盖原有的表达式）@author tangli
     * @date 2025/09/15 13:13
     */
    public fun getSqlSegment(
        table: Table,
        where: Expression?,
        mappedStatementId: String,
        dataScopeValue: DataScopeValue,
    ): Expression?
}
